#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    // enable
    button = new QPushButton(this);
    button->setText("按钮");
    // 按钮就处于禁用状态了
    button->setEnabled(false);

    connect(button, &QPushButton::clicked, this, &Widget::handle);

    // geometry  实际是在改变左上角的坐标

}

Widget::~Widget()
{
    delete ui;
}

void Widget::handle()
{
    qDebug() << "handle";
}


void Widget::on_pushButton_enable_clicked()
{
    qDebug() << "切换按钮的可用状态";
    // 获取可用状态
    bool enable = button->isEnabled();
    if(enable){
        button->setEnabled(false);
    }else{
        button->setEnabled(true);
    }
}

void Widget::on_pushButton_up_clicked()
{
    // 获取到 target 本身的 geometry
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;

    // 实际是在改变左上角的坐标 高度和宽度也变了
//    rect.setY(rect.y() - 5);
//    ui->pushButton_target->setGeometry(rect);

    // 整体移动
    ui->pushButton_target->setGeometry(rect.x(), rect.y() - 5, rect.width(), rect.height());
}

void Widget::on_pushButton_down_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;

//    rect.setY(rect.y() + 5);
//    ui->pushButton_target->setGeometry(rect);

    ui->pushButton_target->setGeometry(rect.x(), rect.y() + 5, rect.width(), rect.height());
}

void Widget::on_pushButton_left_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;

//    rect.setX(rect.x() - 5);
//    ui->pushButton_target->setGeometry(rect);

    ui->pushButton_target->setGeometry(rect.x() - 5, rect.y(), rect.width(), rect.height());
}

void Widget::on_pushButton_right_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;
//    rect.setX(rect.x() + 5);
//    ui->pushButton_target->setGeometry(rect);

    ui->pushButton_target->setGeometry(rect.x() + 5, rect.y(), rect.width(), rect.height());
}
